#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string,int> mp;
int main(){
	int n;
	string name;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> name;
		mp[name]++;
	}
	cout << mp.size() << endl;
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
		cout << it->first << " " << it->second << endl;
	}
}
